package rmmk.algorithms.knn;
/*
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.ml.CvKNearest;

import rmmk.algorithms.features.FeatureManager;
import rmmk.framework.datasources.Document;
import rmmk.opencv.OpenCV;

public class KnnAlgorithmOpenCv {

	private final static Logger logger = Logger.getLogger("KnnLogger"); 
	
	HashMap<Document, Double[]> featuresVector = new HashMap<>();
	private CvKNearest knnAlgorithm;
		
	public KnnAlgorithmOpenCv(List<Document> trainSet,
			FeatureManager fm){
		knnAlgorithm = new CvKNearest();
		if (trainSet.size() == 0)
			return;

		for (Document row : trainSet) {

			Double[] vector = fm.calculateFeatureFor(row);

			featuresVector.put(row, vector);
		}
		
	}
		
	private float classify(Mat sample,int k){
		float result;
		result = knnAlgorithm.find_nearest(sample,k,new Mat(),new Mat(),new Mat());
		return result;
	}
	
	public Map<String,Mat> classifyAndGetDetails(Mat samples,int k){
		//mapa zawierajaca: wynik klasyfikacji, liste najblizszych sasiadow, dystansy do sasiadow.
		Map<String,Mat> resultMap = new HashMap<String,Mat>();
		matResults = new Mat(samples.rows(), samples.cols(), CvType.CV_32FC1);
		matNeighbours = new Mat(samples.rows(),k, CvType.CV_32FC1);
		matDistances = new Mat(samples.rows(),k, CvType.CV_32FC1);
		
		knnAlgorithm.find_nearest(samples,k,matResults,matNeighbours,matDistances);
		resultMap.put("results",matResults);
		resultMap.put("distances",matDistances);
		resultMap.put("neighbours", matNeighbours);
		
		return resultMap;
	}
	
	public Document calculate(Document document,int k){
		
		
		
		return document;
	}
	
	public void teach(){
		
		
	}
	
	private Mat matResults;
	private Mat matNeighbours;
	private Mat matDistances;

	
	public static void main(String[] args) {
	
		KnnAlgorithmOpenCv knn = new KnnAlgorithmOpenCv(new ArrayList<Document>(), new FeatureManager());
		OpenCV.init();
		double[] testData = {1.0,1.0,2.0};
		Mat matTestSet = new Mat(1, 3, CvType.CV_32FC1);
	    int k = 2;
		
		
		matTestSet.put(0, 0, testData);
		float result = knn.classify(matTestSet,k);
		
		logger.info("Result: "+result);
	}
	private static double[] doubleArrayToPrimitive(Double[] array){
		double[] result = new double[array.length];
		for (int i = 0; i < array.length; i++) {
				result[i] = array[i];
		}
		return result;
	}
	
	public static Mat generateMatTrainingData(ArrayList<ArrayList<Double>> trainData){
		Mat matTrainSet = new Mat(trainData.size(),trainData.get(0).size(), CvType.CV_32FC1);
		for (int i = 0; i < trainData.size(); i++) {
			Double row[] = (Double[]) trainData.get(i).toArray();
			double[] resultRow = doubleArrayToPrimitive(row);
			matTrainSet.put(i, 0, resultRow);
			}
		return matTrainSet;
	}
	
	public static Mat generateMatResponsesData(ArrayList<Double> responsesData){
		Mat matResponsesSet = new Mat(responsesData.size(), 1, CvType.CV_32FC1);
		for (int i = 0; i < responsesData.size(); i++) {
			matResponsesSet.put(i, 0, responsesData.get(i));
		}
		return matResponsesSet;
	}
	
}*/